<?php

namespace app\common\model;

use app\common\exception\BusinessException;

class VideoCollection extends Base
{
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';


    public function updateSaleNum($id)
    {
        // 更新条件
        $where = [
            ['id', '=', $id],
        ];
        $isUpdate = $this->where($where)->inc('sale_num', 1)->update();
        if (!$isUpdate) {
            throw new BusinessException('更新销售量失败');
        }
    }
    
    /**
     * 通过课程ID获取所有视频合集的主键ID
     * @param int $courseId 课程ID
     * @return array 视频合集ID数组
     */
    public function getIdsByCourseId($courseId)
    {
        return $this->where('course_id', $courseId)
            ->column('id');
    }
}